package cn.mumzone.pos.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import cn.mumzone.basic.base.BaseActivity;
import cn.mumzone.pos.BuildConfig;
import cn.mumzone.pos.R;
import cn.mumzone.pos.util.AppUtil;

/**
 * Created by qiuzhenhuan on 2019/7/14.
 */

public class ACT_VersionInfo extends BaseActivity {

    @BindView(R.id.tv_current_version)
    TextView tvCurrentVersion;
    @BindView(R.id.iv_new_version)
    ImageView ivNewVersion;
    @BindView(R.id.tv_update_version)
    TextView tvUpdateVersion;
    @BindView(R.id.iv_go_right)
    ImageView ivGoRight;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        overridePendingTransition(cn.mumzone.basic.R.anim.right_in, cn.mumzone.basic.R.anim.right_out);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.gravity = Gravity.RIGHT;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(params);
        getWindow().setBackgroundDrawableResource(R.color.bg_color);
    }

    @Override
    protected void initEventAndData() {

        tvCurrentVersion.setText(String.format("当前版本V%s", BuildConfig.VERSION_NAME));
        ivNewVersion.setVisibility(AppUtil.isNeedUpdate() ? View.VISIBLE : View.GONE);
        ivGoRight.setVisibility(AppUtil.isNeedUpdate() ? View.VISIBLE : View.GONE);
        tvUpdateVersion.setText(AppUtil.isNeedUpdate() ? "立即更新" : "最新版本");

    }

    @OnClick({R.id.iv_close,R.id.iv_back})
    void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_close:
                finish();
                break;
            case R.id.iv_back:
                ACT_Setting.startAc(mContext);
                finish();
                break;
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        ACT_Setting.startAc(mContext);
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected int getLayout() {
        return R.layout.act_version_info;
    }

    public static void startAc(Context context) {
        Intent intent = new Intent(context, ACT_VersionInfo.class);
        context.startActivity(intent);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(cn.mumzone.basic.R.anim.right_in, cn.mumzone.basic.R.anim.right_out);
    }
}
